---
category: Level 1 — Basic
created: '2020-04-19'
keywords: get selected text, window getSelection
title: Get the selected text
---

```js
const selectedText = window.getSelection().toString();
```

## See also

-   [Copy highlighted code to the clipboard](https://phuoc.ng/collection/html-dom/copy-highlighted-code-to-the-clipboard/)
-   [Get the direction of the text selection](https://phuoc.ng/collection/html-dom/get-the-direction-of-the-text-selection/)
-   [Paste as plain text](https://phuoc.ng/collection/html-dom/paste-as-plain-text/)
-   [Save and restore the text selection](https://phuoc.ng/collection/html-dom/save-and-restore-the-text-selection/)
-   [Select the text content of an element](https://phuoc.ng/collection/html-dom/select-the-text-content-of-an-element/)
